package main

import (
	"github.com/hyperledger/fabric/core/chaincode/shim"
	"github.com/hyperledger/fabric/core/chaincode/shim/ext/cid"
	"github.com/hyperledger/fabric/protos/peer"
)

type RentContract struct {
	Leaseholder string
	Tenant string
	Deposit string
	Rent   int32
	PayCycle int8
	Remark  string
}

func (rc RentContract) Init(stub shim.ChaincodeStubInterface) peer.Response {
	return shim.Success(nil)
}

func (rc RentContract) Invoke(stub shim.ChaincodeStubInterface) peer.Response {
	funcName, args := stub.GetFunctionAndParameters()
	switch funcName {
	case "initiate":
		return rc.initiate(stub, args)
	case "sign":
		return rc.sign(stub, args)
	}
	return shim.Success(nil)
}

//
func (rc RentContract) initiate(stub shim.ChaincodeStubInterface, args []string) peer.Response {
	if len(args) != 1 {
		return shim.Error("invalid args")
	}
	clientID, err := cid.New(stub)
	if err != nil {
		return shim.Error("invalid err")
	}
	clientID.GetMSPID()
	return shim.Success(nil)
}

// sign contract
func (rc RentContract) sign(stub shim.ChaincodeStubInterface, args []string) peer.Response {
	return shim.Success(nil)
}

func main() {
	rc := RentContract{}
	shim.Start(rc)
}